package com.igeekhome.controller.api;

import com.igeekhome.pojo.DNetwork;
import com.igeekhome.pojo.SysRole;
import com.igeekhome.service.IStaffService;
import com.igeekhome.service.ISysPermissionService;
import com.igeekhome.service.ISysRoleService;
import com.igeekhome.util.ResultBean;
import com.igeekhome.util.TableResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;


/**
 * @author 汪璇
 */
@RestController
@RequestMapping("/api/system")
public class SystemControllerApi {
    
    @Autowired
    private IStaffService staffService;
    
    @Autowired
    private ISysRoleService roleService;
    
    @Autowired
    private ISysPermissionService powerService;
    
    //角色分配列表
    @RequestMapping("/roleManage")
    public TableResultBean ruleManage(HttpSession session, Integer page, Integer limit) {
        DNetwork network = (DNetwork) session.getAttribute("network");
        return staffService.selectByNetworkId(network, page, limit);
    }
    
    //角色管理返回角色dtree数据
    @RequestMapping("/roleList")
    public ResultBean roleList() {
        return roleService.roleList(roleService.selectAllRole());
    }
    
    /**
     * @Description 设置角色
     * @Param [staffId, roleId]
     * @Return com.igeekhome.util.ResultBean
     **/
    @RequestMapping("setRole")
    public ResultBean setRole(Integer staffId, Integer roleId) {
        System.out.println("----------------------------------------------------------------------------------");
        System.out.println(staffId+"=========="+roleId);
        System.out.println("----------------------------------------------------------------------------------");
        
        return roleService.setRole(staffId,roleId);
    }
    /**
     * @Description 设置角色权限
     * @Param [staffId, roleId]
     * @Return com.igeekhome.util.ResultBean
     **/
    @RequestMapping("disRole")
    public ResultBean disRole(Integer[] powerId, Integer roleId) {
        return roleService.disRole(powerId,roleId);
    }
    
    //权限分配中角色列表
    @RequestMapping("/powerManage")
    public TableResultBean powerManage(Integer page, Integer limit) {
        return roleService.roles(page, limit);
    }
    
    //角色管理返回权限dtree数据
    @RequestMapping("/powerList")
    public ResultBean powerList() {
        return powerService.powerList();
    }
    
    //角色编辑
    @RequestMapping("/editRole")
    public ResultBean editRole(SysRole role) {
        return roleService.editRole(role);
    }
    
    //角色新增
    @RequestMapping("/addRole")
    public ResultBean addRole(SysRole role) {
        return roleService.addRole(role);
    }
    
    //角色删除
    @RequestMapping("/delRole")
    public ResultBean delRole(Integer id) {
        return roleService.delRole(id);
    }
    
}

    
